package com.itheima.HomeWork.homework06;

import java.io.FileWriter;
import java.io.IOException;

public class Demo01 {

    public static void main(String[] args) throws IOException {
        test1();
        test2();
    }

    public static void test1() throws IOException {
        FileWriter fw = null;
        //TODO
        // 请使用FileWriter向文件输出：HelloWorld
        // 用 try-catch-finally 方式处理异常。
        try {
            fw = new FileWriter("E:\\img1\\a.txt");
            fw.write("HelloWord");

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fw != null) {
                try {
                    fw.close();
                } catch (IOException e) {
                   e.printStackTrace();
                }
            }
        }
    }


    public static void test2() {
        //TODO
        // 请使用FileWriter向文件输出：HelloWorld
        // 用 try-with-resource 方式处理异常。
        try (FileWriter fw = new FileWriter("E:\\img1\\a.txt");) {
            fw.write("HelloWord");
        } catch (Exception e) {
            e.printStackTrace();

        }
    }
}
